import java.awt.*;


import javax.swing.*;

import net.miginfocom.swing.MigLayout;


public class WagonInventoryPanel extends JPanel {

	/**
	 * This panel holds the list of items the player has in their wagon('s inventory)
	 * 
	 * @author Amy Lambeth
	 * @version 2.0 10/19/2011
	 */
	
	private static final long serialVersionUID = 1L;
	DefaultListModel model;
	JList list;
	private InventoryController invControl=new InventoryController();
	private Inventory wagonInv=invControl.getWagonInventory();	//Get instance of Wagon Inventory
	
	/**
	 * Create the panel.
	 */
	public WagonInventoryPanel() {
		
		setLayout(new MigLayout("", "[69.00][94.00][98.00][61.00]", "[][29.00][32.00][29.00][29.00][30.00][29.00][30.00]"));
		
		JLabel lblPrice = new JLabel("Price");
		add(lblPrice, "cell 1 0");
		
		JLabel lblQuantity = new JLabel("Quantity");
		add(lblQuantity, "cell 3 0");
		
		JLabel lblOxen = new JLabel("Oxen");
		add(lblOxen, "cell 0 1");
		
		JLabel lblNewLabel = new JLabel("Weight");
		add(lblNewLabel, "cell 2 0,aligny top");
		
		JLabel lblfor = new JLabel("$40 (for 2)");
		add(lblfor, "cell 1 1");
		
		JLabel lblnone = new JLabel("(none)");
		add(lblnone, "cell 2 1");
		
		JLabel label_4 = new JLabel("0");
		add(label_4, "cell 3 1");
		
		JLabel lblFood = new JLabel("Food");
		add(lblFood, "cell 0 2");
		
		JLabel lblfor_1 = new JLabel("$1");
		add(lblfor_1, "cell 1 2");
		
		JLabel lblLbs = new JLabel("5 lbs");
		add(lblLbs, "cell 2 2");
		
		JLabel label_5 = new JLabel("0");
		add(label_5, "cell 3 2");
		
		JLabel lblClothing = new JLabel("Clothing");
		add(lblClothing, "cell 0 3");
		
		JLabel label = new JLabel("$10");
		add(label, "cell 1 3");
		
		JLabel lblLbs_1 = new JLabel("2 lbs");
		add(lblLbs_1, "cell 2 3");
		
		JLabel label_6 = new JLabel("0");
		add(label_6, "cell 3 3");
		
		JLabel lblAmmunition = new JLabel("Ammo");
		add(lblAmmunition, "cell 0 4");
		
		JLabel lblRounds = new JLabel("$2 (for 20)");
		add(lblRounds, "cell 1 4");
		
		JLabel lblLbs_5 = new JLabel("3 lbs");
		add(lblLbs_5, "cell 2 4");
		
		JLabel label_7 = new JLabel("0");
		add(label_7, "cell 3 4");
		
		JLabel lblWheel = new JLabel("Wheel");
		add(lblWheel, "cell 0 5");
		
		JLabel label_1 = new JLabel("$10");
		add(label_1, "cell 1 5");
		
		JLabel lblLbs_2 = new JLabel("75 lbs");
		add(lblLbs_2, "cell 2 5");
		
		JLabel label_8 = new JLabel("0");
		add(label_8, "cell 3 5");
		
		JLabel lblAxle = new JLabel("Axle");
		add(lblAxle, "cell 0 6");
		
		JLabel label_2 = new JLabel("$10");
		add(label_2, "cell 1 6");
		
		JLabel lblLbs_3 = new JLabel("125 lbs");
		add(lblLbs_3, "cell 2 6");
		
		JLabel label_9 = new JLabel("0");
		add(label_9, "cell 3 6");
		
		JLabel lblTongue = new JLabel("Tongue");
		add(lblTongue, "cell 0 7");
		
		JLabel label_3 = new JLabel("$10");
		add(label_3, "cell 1 7");
		
		JLabel lblLbs_4 = new JLabel("100 lbs");
		add(lblLbs_4, "cell 2 7");
		
		JLabel label_10 = new JLabel("0");
		add(label_10, "cell 3 7");
		//model = new DefaultListModel();
		
		//Create new InventoryController
		
		
		
		
		
		//Set up JList for Wagon Inventory
		/*list = new JList(model);
		list.setToolTipText("Wagon Inventory");
		list.setValueIsAdjusting(true);
		JScrollPane bar = new JScrollPane(list);
		bar.setMinimumSize(new Dimension(300,100));
		add(bar);
		
		for (Item item:wagonInv){
			model.addElement(item.getName()+"\t Quantity:"+item.getQuantity()+
					"\t Weight:"+item.getWEIGHT_INDIVIDUAL()+"\t Price:"+item.getPRICE());
		}
				
		MouseListener listener = new MouseAdapter(){
			int answer;
			int delimiter;
			public void mouseClicked(MouseEvent e){
				if(e.getClickCount()==2){
					boolean valid = false;
					while(!valid)
					try{

						 answer = Integer.parseInt(JOptionPane.showInputDialog("How much of " + ((String)model.getElementAt(list.getSelectedIndex())).trim() + " would you like to sell"));
						valid = true;
					}
					catch(Exception exception){
					}
					
					String current = (String) model.getElementAt(list.getSelectedIndex());
					//Repopulate item if number to sell is changed to zero.
					if (answer==0){
						for (Item item:wagonInv){
							model.addElement(item.getName()+"\t Quantity:"+item.getQuantity()+
									"\t Weight:"+item.getWEIGHT_INDIVIDUAL()+"\t Price:"+item.getPRICE());
						}
					}
					else{
					delimiter = current.indexOf("Quantity:");
					current = current.substring(0, delimiter) + "Selling: " + answer;
					model.setElementAt(current, list.getSelectedIndex());
					System.out.println("done");
					}
				}

			}
		};
		list.addMouseListener(listener);
	}*/
	}
}
